        $(document).ready(function () {
            
            // prepare the data
            var source =
            {
                dataType: "csv",
                dataFields: [
                     { name: 'ezId', type: 'string' },
                     { name: 'cp', type: 'string' },
                     { name: 'secType', type: 'string' },
                     { name: 'cpId', type: 'string' },
                     { name: 'underlier', type: 'string' },
                     { name: 'MV_Diff', type: 'string' }
                ], 
                url: 'assets/sampledata/CollateralOverview.csv'
            };
            var dataAdapter = new $.jqx.dataAdapter(source, {
                loadComplete: function () {
                    // data is loaded.
                }
            });
            var cellClass = function (row, dataField, cellText, rowData) {
                var cellValue = rowData[dataField];
                switch (dataField) {
                    case "diffQuantity":
                        if (cellValue >100 || cellValue < 0) {
                            return "minavg";                            
                        }
                        if (cellValue <= 100 ) {
                            return "max";
                        }                       
                        return "max";
                        
                    case "diffMarketValue":
                        if (cellValue >100 || cellValue < 0) {
                            return "minavg";                            
                        }
                        if (cellValue <= 100 ) {
                            return "max";
                        }                        
                        return "min";                    
                }
            };
            // create jqxDataTable.
            $("#CollateralOverview").jqxGrid(
            {
                source: dataAdapter,
                altRows: true,
                width: '99%',
                height: '600',
                sortable: true,
                pageable:false,
                filterable: true,
                groupable: true,
                showaggregates: true,
                columnsresize: true,
                columnsreorder: true,
                columns: [
                  { text: 'Counterparty', cellsAlign: 'center',columngroup: 'ProductDetails', align: 'center', dataField: 'ezId',/* pinned: true,*/  width: '20%' },
                  { text: 'Collateral Balance', cellsAlign: 'center',columngroup: 'ProductDetails', align: 'center', dataField: 'cp', width: '20%' },
                  { text: 'Todays Collateral Change', dataField: 'secType',columngroup: 'ProductDetails', cellsformat: 'c2', align: 'center', cellsAlign: 'center', width: '20%' },
                  { text: 'CP MV',columngroup: 'ProductDetails', dataField: 'cpId', cellsformat: 'd', cellsAlign: 'center', align: 'center', width: '20%' },
                  { text: 'EZ MV', cellsAlign: 'center', align: 'center', dataField: 'underlier', width: '20%'},
                  { text: 'MV Diff', cellsAlign: 'center', align: 'center', dataField: 'MV_Diff', width: '20%'
                     }
                ]
                
            });  
            
            $(function() {
        		var chart;
        		$(document).ready(function() {
        			// Build the chart4
        			$('#containerpie3').highcharts({
        				chart : {
        					type : 'bar'
        				},
        				title : {
        					text : ''
        				},
        				subtitle : {
        					text : ''
        				},
        				xAxis : {
        					categories : [ 'JPM', 'CS', 'Citi', 'MS', 'GS' ]
        				},
        				credits : {
        					enabled : false
        				},
        				series : [ {
        					name : 'Today Collateral Change',
        					data : [ 11000000, -1000000, 0, 2500000, 450000 ]

        				} ]
        			});
        		});

        	});
        });
    $(document).ready(function () {
 // Master Aggrement Final Grid
    
    var source =
    {
     dataType: "json",
     dataFields: [
			{ name: 'entityId', type: 'string' },
			{ name: 'valuationMarketPlace', type: 'string' },
			{ name: 'agreementType', type: 'string' },
			{ name: 'id', type: 'string' },
			{ name: 'partyId', type: 'string' },
			{ name: 'signedDate', type: 'string' }

     ], 
     url: ezopsContextPath+'/getReports/getmasteraggrementfinalgrid'
 };
 var dataAdapter = new $.jqx.dataAdapter(source, {
     loadComplete: function () {
         //console.log(dataAdapter);
     }
 });
 var cellClass = function (row, dataField, cellText, rowData) {
     var cellValue = rowData[dataField];
     switch (dataField) {
         case "diffQuantity":
             if (cellValue >100 || cellValue < 0) {
                 return "minavg";                            
             }
             if (cellValue <= 100 ) {
                 return "max";
             }                       
             return "max";
             
         case "diffMarketValue":
             if (cellValue >100 || cellValue < 0) {
                 return "minavg";                            
             }
             if (cellValue <= 100 ) {
                 return "max";
             }                        
             return "min";                    
     }
 };
			
         $("#masterAggrementFinal").jqxGrid(
         {
             source: dataAdapter,
             altRows: true,
             width: '99%',
             height: '600',
             sortable: true,
             pageable:false,
             filterable: true,
             groupable: true,
             showstatusbar: true,
             statusbarheight: 50,
             showaggregates: true,
             columnsresize: true,
             columnsreorder: true,

             
             columns: [
				{text:'EntityId',dataField:'entityId',cellsAlign: 'center',columngroup: 'ProductDetails', align: 'center',  width: '100px'},
				{text:'Valuation Market Place',dataField:'valuationMarketPlace',cellsAlign: 'center',columngroup: 'ProductDetails', align: 'center',  width: '100px'},
				{text:'Agreement Type',dataField:'agreementType',cellsAlign: 'center',columngroup: 'ProductDetails', align: 'center',  width: '100px'},
				{text:'Id',dataField:'id',cellsAlign: 'center',columngroup: 'ProductDetails', align: 'center',  width: '100px'},
				{text:'PartyId',dataField:'partyId',cellsAlign: 'center',columngroup: 'ProductDetails', align: 'center',  width: '100px'},
				{text:'Signed Date',dataField:'signedDate',cellsAlign: 'center',columngroup: 'ProductDetails', align: 'center',  width: '100px'}
             ]
             
         });  
         
        /* Chart data for Master Agreement Report */
        var masterAgreementJsonBarSeriesData = new Array();
     	var masterAgreementJsonBarCategories = new Array();
     	var masterAgreementJson = new Array();
         $.getJSON(
 				ezopsContextPath
 						+ '/getReports/getmasteragreemengpiechart',
 				function(data) {
 					for ( var i = 0, len = data.length; i < len; i++) {
 						//masterAgreementJsonBarCategories.push([data[i].partyId]);
 						//masterAgreementJsonBarSeriesData.push([parseInt(data[i].agreementTypeCount)]);
 						masterAgreementJson.push([ data[i].partyId,parseInt(data[i].agreementTypeCount) ]);
 					}
 					getPositionByCpReport(masterAgreementJson);
 					$('.loaddiv').hide();
 				});
         
          $.getJSON(
  				ezopsContextPath
  						+ '/getReports/getmasteragreemengpiechart',
  				function(data) {
  					for ( var i = 0, len = data.length; i < len; i++) {
  						masterAgreementJsonBarCategories.push([data[i].partyIdList]);
  						masterAgreementJsonBarSeriesData.push([parseInt(data[i].masterAggrementAgreementCountModelList)]);
  						//masterAgreementJson.push([ data[i].partyId,parseInt(data[i].agreementTypeCount) ]);
  					}
  					getPositionByCpReport(masterAgreementJson);
  					$('.loaddiv').hide();
  				});
         
         var masterReportChecked =  'true';
         $('#master-chart-view1').on('click', function(event) {
         	if(masterReportChecked){
             	$('#masterAggrementFinalChart')
             	.highcharts(
             			{
             				chart : {
             					type : 'bar'
             				},

             				title : {
             					text : ''
             				},
             				subtitle : {
             					text : ''
             				},

             				xAxis : {
             					categories : masterAgreementJsonBarCategories
             				},
             				credits : {
             					enabled : false
             				},
             				series : [ {
             					name : 'Cash Amount',
             					data : masterAgreementJsonBarSeriesData

             				} ]
             			});
             	masterReportChecked = 'false';
             }
         	else{
         		masterReportChecked = 'true';
         		getPositionByCpReport(masterAgreementJson);
         	}

         });
         function getPositionByCpReport(masterAgreementJson) {
				// Build the chart4
				//console.log('processed_json');
				//console.log(masterAgreementJson);
				$('#masterAggrementFinalChart')
				.highcharts(
						{
							chart : {
								plotBackgroundColor : null,
								plotBorderWidth : null,
								plotShadow : false
							},
							title : {
								text : ''
							},
							/* tooltip : {
								pointFormat : 'Quantity: <b>{point.percentage:.1f}%</b>'
							}, */
							plotOptions : {
								pie : {
									allowPointSelect : true,
									cursor : 'pointer',
									dataLabels : {
										enabled : false
									},
									showInLegend : true
								}
							},
							series : [ {
								type : 'pie',
								name : '',
								data : masterAgreementJson
							} ]
						});
		
			}	    
});